import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:photo_view/photo_view_gallery.dart';

class PhotoViewGalleryScreen extends StatefulWidget {
  final Map arguments;
  PhotoViewGalleryScreen({Key key, this.arguments}) : super(key: key);

  @override
  State<StatefulWidget> createState() => MyState();
}

class MyState extends State<PhotoViewGalleryScreen> {
  int currentIndex=0;

  @override
  void initState() {
    super.initState();
    currentIndex = widget.arguments['index'];
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Stack(
        children: <Widget>[
          Positioned(
            top: 0,
            left: 0,
            bottom: 0,
            right: 0,
            child: Container(
              color: Colors.black,
              child: PhotoViewGallery.builder(
                scrollPhysics: const BouncingScrollPhysics(),
                builder: (BuildContext context, int index) {
                  return PhotoViewGalleryPageOptions(
                    imageProvider: NetworkImage(widget.arguments['list'][index]),
                  );
                },
                itemCount: widget.arguments['list'].length,
                backgroundDecoration: null,
                pageController: PageController(initialPage: widget.arguments['index']),
                enableRotation: true,
                onPageChanged: (index){
                  setState(() {
                    currentIndex=index;
                  });
                },
              )
            ),
          ),
          //图片index显示
          Positioned(
            top: MediaQuery.of(context).padding.top+15,
            width: MediaQuery.of(context).size.width,
            child: Center(
              child: Text("${currentIndex+1}/${widget.arguments['list'].length}",
              style: TextStyle(color: Colors.white,fontSize: 16)),
            ),
          ),
          Positioned(
            //右上角关闭按钮
            right: 10,
            bottom: MediaQuery.of(context).padding.top,
            child: IconButton(
              icon: Icon(
                Icons.close,
                size: 30,
                color: Colors.white,
              ),
              onPressed: () {
                Navigator.of(context).pop();
              },
            ),
          ),
        ],
      ),
    );
  }

  // @override
  // Widget build(BuildContext context) {
  //   ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: false);

  //   return DefaultTabController(
  //     length: 3,
  //     initialIndex: 0,
  //     child: Scaffold(
  //       appBar: TopBar(
  //         title: '物资详情',
  //         backgroundColor: Utils.hexToColor('#297CFF'),
  //       ),
  //       body: Text('123')
  //     )
  //   );
  // }
}
